class CommentsController < ApplicationController
	before_filter :authenticate, :only => [:destroy]

	def create
		@post = Post.find(params[:post_id])
		@comment = @post.comments.create!(params[:comment])
		respond_to do |format|
			format.html { redirect_to @post }
			format.js
		end
    end

	def destroy
		@comment = Comment.find(params[:id])
		@comment.destroy

		respond_to do |format|
			flash[:notice] = 'Commentaire correctement supprim&eacute;.'
			format.html { redirect_to(:controller => :posts, :action => :show, :id => params[:post_redirect_id]) }
			format.xml  { head :ok }
		end
	end

	private
		def authenticate
			authenticate_or_request_with_http_basic do |name, password|
				name == "Nami" && password = "motdepasse"
#				name == "U can add" && password == "All users u need"
		end
	end
end